<template>
    <div class="goods-list">
        <div class="goods-item" v-for="goods in newGoodsList" :key="goods.id">
            <van-icon name="arrow-left" class="back-btn" @click="$router.go(-1)" />
            <div class="goods-img-container">
                <img :src="goods.picUrl" :alt="goods.title" class="goods-img">
                <div class="goods-info-center">
                    <div class="goods-title">{{ goods.title }}</div>
                    <div class="goods-read">阅读次数：“{{ goods.readCount }}”</div>
                </div>
            </div>
            <div class="goods-desc">{{ goods.subtitle }}</div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { getmoreztjx } from "@/api/home";

const newGoodsList = ref([]);
const totalPages = 2;

onMounted(async () => {
    for (let page = 1; page <= totalPages; page++) {
        const response = await getmoreztjx(page, 10);
        if (response.data && response.data.list) {
            newGoodsList.value.push(...response.data.list);
        }
    }

});
</script>

<style scoped>
.goods-list {
    min-width: 78vh;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.goods-item {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 20px;
}

.goods-img-container {
    position: relative;
    width: 100%;
    padding-top: 60%;
    overflow: hidden;
    border-radius: 12px;
    background-color: #f5f5f5;
}

.goods-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.goods-img-container:hover .goods-img {
    transform: scale(1.02);
}

.goods-info-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
    width: 80%;
}

.goods-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.goods-read {
    font-size: 20px;
    font-weight: bold;
    color: #fff;
    display: inline-block;
    padding: 5px 16px;
}

.goods-desc {
    font-size: 16px;
    color: #555;
    line-height: 1.5;
    padding: 0 10px;
}
.back-btn {
    position: absolute;
    top: 25px;
    left: 370px;
    color: white;
    font-size: 20px;
    background: gainsboro;
    border-radius: 50%;
    padding: 8px;
    z-index: 1;
}
</style>
3